package com.bw.hxc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.hxc.entity.Result;
import com.bw.hxc.entity.Search;
import com.bw.hxc.entity.Ticketv;
import com.bw.hxc.service.ITicketService;
import com.bw.hxc.service.ITicketvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 黄旭超
 * @since 2022-05-26
 */
@RestController
@RequestMapping("/ticket")
public class TicketController {
    @Autowired
    ITicketService ticketService;

    @Autowired
    ITicketvService ticketvService;

    @RequestMapping("list")
    public Page<Ticketv> list(@RequestBody Search search){
        Page<Ticketv> page = new Page<>(search.getPage(),search.getPageSize());
        QueryWrapper<Ticketv> wrapper = new QueryWrapper<>();
        if (search.getStationId()>0){
            wrapper.eq("start_station",search.getStationId());
        }
        if (search.getStartDate()!=null){
            wrapper.gt("buy_date",search.getStartDate());
        }
        if (search.getEndDate()!=null){
            wrapper.lt("buy_date",search.getEndDate());
        }
        if (search.getName()!=null && search.getName() !=""){
            wrapper.like("username",search.getName());
        }
        Page<Ticketv> page1 = ticketvService.page(page, wrapper);
        return page1;
    }

    @RequestMapping("del")
    public Result del(int id){
        boolean b = ticketService.removeById(id);
        if (b){
            return new Result(200,"","删除成功");
        }else {
            return new Result(201,"","删除失败");
        }
    }

}
